{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ -3.64258661  -8.76425054   6.89554461  -0.2785054 ]\n",
      " [ -6.17627811   3.05680197  -3.00481127  -5.06588089]\n",
      " [-11.36464378   5.08603271  -1.3193706   -5.92492884]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(12,)"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.random.normal(0,5,(3,4))\n",
    "print(arr)\n",
    "arr.ravel().shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "80"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nwalk = 10\n",
    "nstep = 1000\n",
    "drw = np.random.randint(0,2,size=(nwalk,nstep))\n",
    "drw = np.where(drw>0,1,-1)\n",
    "walk = np.cumsum(drw,axis=1)\n",
    "walk.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ True  True False  True  True  True  True False False  True]\n"
     ]
    }
   ],
   "source": [
    "dd = (np.abs(walk) >= 30).any(1)\n",
    "print(dd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([365, 877, 167, 775, 945, 777, 221])"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(np.abs(walk[dd])>=30).argmax(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-9.05623199,  1.27160366,  3.29280923,  5.94292503],\n",
       "       [-7.71252336,  2.00315041,  5.11025332,  8.20455044],\n",
       "       [-2.37292334,  4.83605059,  9.36557216, 11.33681852]])"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.sort(axis=0)\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on class flatiter in module numpy:\n",
      "\n",
      "class flatiter(builtins.object)\n",
      " |  Flat iterator object to iterate over arrays.\n",
      " |  \n",
      " |  A `flatiter` iterator is returned by ``x.flat`` for any array `x`.\n",
      " |  It allows iterating over the array as if it were a 1-D array,\n",
      " |  either in a for-loop or by calling its `next` method.\n",
      " |  \n",
      " |  Iteration is done in row-major, C-style order (the last\n",
      " |  index varying the fastest). The iterator can also be indexed using\n",
      " |  basic slicing or advanced indexing.\n",
      " |  \n",
      " |  See Also\n",
      " |  --------\n",
      " |  ndarray.flat : Return a flat iterator over an array.\n",
      " |  ndarray.flatten : Returns a flattened copy of an array.\n",
      " |  \n",
      " |  Notes\n",
      " |  -----\n",
      " |  A `flatiter` iterator can not be constructed directly from Python code\n",
      " |  by calling the `flatiter` constructor.\n",
      " |  \n",
      " |  Examples\n",
      " |  --------\n",
      " |  >>> x = np.arange(6).reshape(2, 3)\n",
      " |  >>> fl = x.flat\n",
      " |  >>> type(fl)\n",
      " |  <class 'numpy.flatiter'>\n",
      " |  >>> for item in fl:\n",
      " |  ...     print(item)\n",
      " |  ...\n",
      " |  0\n",
      " |  1\n",
      " |  2\n",
      " |  3\n",
      " |  4\n",
      " |  5\n",
      " |  \n",
      " |  >>> fl[2:4]\n",
      " |  array([2, 3])\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __array__(...)\n",
      " |      __array__(type=None) Get array from iterator\n",
      " |  \n",
      " |  __delitem__(self, key, /)\n",
      " |      Delete self[key].\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getitem__(self, key, /)\n",
      " |      Return self[key].\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __next__(self, /)\n",
      " |      Implement next(self).\n",
      " |  \n",
      " |  __setitem__(self, key, value, /)\n",
      " |      Set self[key] to value.\n",
      " |  \n",
      " |  copy(...)\n",
      " |      copy()\n",
      " |      \n",
      " |      Get a copy of the iterator as a 1-D array.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.arange(6).reshape(2, 3)\n",
      " |      >>> x\n",
      " |      array([[0, 1, 2],\n",
      " |             [3, 4, 5]])\n",
      " |      >>> fl = x.flat\n",
      " |      >>> fl.copy()\n",
      " |      array([0, 1, 2, 3, 4, 5])\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  base\n",
      " |      A reference to the array that is iterated over.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.arange(5)\n",
      " |      >>> fl = x.flat\n",
      " |      >>> fl.base is x\n",
      " |      True\n",
      " |  \n",
      " |  coords\n",
      " |      An N-dimensional tuple of current coordinates.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.arange(6).reshape(2, 3)\n",
      " |      >>> fl = x.flat\n",
      " |      >>> fl.coords\n",
      " |      (0, 0)\n",
      " |      >>> fl.next()\n",
      " |      0\n",
      " |      >>> fl.coords\n",
      " |      (0, 1)\n",
      " |  \n",
      " |  index\n",
      " |      Current flat index into the array.\n",
      " |      \n",
      " |      Examples\n",
      " |      --------\n",
      " |      >>> x = np.arange(6).reshape(2, 3)\n",
      " |      >>> fl = x.flat\n",
      " |      >>> fl.index\n",
      " |      0\n",
      " |      >>> fl.next()\n",
      " |      0\n",
      " |      >>> fl.index\n",
      " |      1\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  __hash__ = None\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.flatiter\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-7.70789502, 19.24117741,  0.15756769],\n",
       "       [-1.68051379,  8.850964  ,  1.2065751 ],\n",
       "       [ 5.42119663, 47.16344663,  1.66120237]])"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.normal(10,20,(3,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-6.11776942, -3.74685401, -6.18334598, -0.34044558],\n",
       "       [ 1.66154041, -1.01921478, -2.52757949,  2.53925114],\n",
       "       [ 3.52612458,  8.58687142, -1.07249641,  3.50296689]])"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sort(arr,axis = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3,)"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.ones(3)\n",
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-3 -2 -1  0  1  2]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "-0.5"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.arange(-3,3,1)\n",
    "print(x)\n",
    "np.median(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[-3, -2, -1,  0,  1,  2],\n",
       "        [-3, -2, -1,  0,  1,  2],\n",
       "        [-3, -2, -1,  0,  1,  2],\n",
       "        [-3, -2, -1,  0,  1,  2],\n",
       "        [-3, -2, -1,  0,  1,  2],\n",
       "        [-3, -2, -1,  0,  1,  2]]), array([[-3, -3, -3, -3, -3, -3],\n",
       "        [-2, -2, -2, -2, -2, -2],\n",
       "        [-1, -1, -1, -1, -1, -1],\n",
       "        [ 0,  0,  0,  0,  0,  0],\n",
       "        [ 1,  1,  1,  1,  1,  1],\n",
       "        [ 2,  2,  2,  2,  2,  2]])]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.meshgrid(x,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.11022655,  0.30894953,  1.01647462,  1.90626295],\n",
       "       [ 1.94216806, -2.3526402 ,  1.88324254,  0.70667794],\n",
       "       [-7.08106825, -2.17938289,  1.56011001, -1.75927149]])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(0,5,(3,4))\n",
    "np.random.normal(0,5,(3,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function randn:\n",
      "\n",
      "randn(...) method of numpy.random.mtrand.RandomState instance\n",
      "    randn(d0, d1, ..., dn)\n",
      "    \n",
      "    Return a sample (or samples) from the \"standard normal\" distribution.\n",
      "    \n",
      "    .. note::\n",
      "        This is a convenience function for users porting code from Matlab,\n",
      "        and wraps `numpy.random.standard_normal`. That function takes a\n",
      "        tuple to specify the size of the output, which is consistent with\n",
      "        other NumPy functions like `numpy.zeros` and `numpy.ones`.\n",
      "    \n",
      "    If positive int_like arguments are provided, `randn` generates an array\n",
      "    of shape ``(d0, d1, ..., dn)``, filled\n",
      "    with random floats sampled from a univariate \"normal\" (Gaussian)\n",
      "    distribution of mean 0 and variance 1. A single float randomly sampled\n",
      "    from the distribution is returned if no argument is provided.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    d0, d1, ..., dn : int, optional\n",
      "        The dimensions of the returned array, must be non-negative.\n",
      "        If no argument is given a single Python float is returned.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    Z : ndarray or float\n",
      "        A ``(d0, d1, ..., dn)``-shaped array of floating-point samples from\n",
      "        the standard normal distribution, or a single such float if\n",
      "        no parameters were supplied.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    standard_normal : Similar, but takes a tuple as its argument.\n",
      "    normal : Also accepts mu and sigma arguments.\n",
      "    \n",
      "    Notes\n",
      "    -----\n",
      "    For random samples from :math:`N(\\mu, \\sigma^2)`, use:\n",
      "    \n",
      "    ``sigma * np.random.randn(...) + mu``\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> np.random.randn()\n",
      "    2.1923875335537315  # random\n",
      "    \n",
      "    Two-by-four array of samples from N(3, 6.25):\n",
      "    \n",
      "    >>> 3 + 2.5 * np.random.randn(2, 4)\n",
      "    array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],   # random\n",
      "           [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]])  # random\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.random.normal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "array = np.array([[1,7,3],\n",
    "                  [2,5,4]],dtype=np.int)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 3, 7],\n",
       "       [2, 4, 5]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sort(array,axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function sort in module numpy:\n",
      "\n",
      "sort(a, axis=-1, kind=None, order=None)\n",
      "    Return a sorted copy of an array.\n",
      "    \n",
      "    Parameters\n",
      "    ----------\n",
      "    a : array_like\n",
      "        Array to be sorted.\n",
      "    axis : int or None, optional\n",
      "        Axis along which to sort. If None, the array is flattened before\n",
      "        sorting. The default is -1, which sorts along the last axis.\n",
      "    kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional\n",
      "        Sorting algorithm. The default is 'quicksort'. Note that both 'stable'\n",
      "        and 'mergesort' use timsort or radix sort under the covers and, in general,\n",
      "        the actual implementation will vary with data type. The 'mergesort' option\n",
      "        is retained for backwards compatibility.\n",
      "    \n",
      "        .. versionchanged:: 1.15.0.\n",
      "           The 'stable' option was added.\n",
      "    \n",
      "    order : str or list of str, optional\n",
      "        When `a` is an array with fields defined, this argument specifies\n",
      "        which fields to compare first, second, etc.  A single field can\n",
      "        be specified as a string, and not all fields need be specified,\n",
      "        but unspecified fields will still be used, in the order in which\n",
      "        they come up in the dtype, to break ties.\n",
      "    \n",
      "    Returns\n",
      "    -------\n",
      "    sorted_array : ndarray\n",
      "        Array of the same type and shape as `a`.\n",
      "    \n",
      "    See Also\n",
      "    --------\n",
      "    ndarray.sort : Method to sort an array in-place.\n",
      "    argsort : Indirect sort.\n",
      "    lexsort : Indirect stable sort on multiple keys.\n",
      "    searchsorted : Find elements in a sorted array.\n",
      "    partition : Partial sort.\n",
      "    \n",
      "    Notes\n",
      "    -----\n",
      "    The various sorting algorithms are characterized by their average speed,\n",
      "    worst case performance, work space size, and whether they are stable. A\n",
      "    stable sort keeps items with the same key in the same relative\n",
      "    order. The four algorithms implemented in NumPy have the following\n",
      "    properties:\n",
      "    \n",
      "    =========== ======= ============= ============ ========\n",
      "       kind      speed   worst case    work space   stable\n",
      "    =========== ======= ============= ============ ========\n",
      "    'quicksort'    1     O(n^2)            0          no\n",
      "    'heapsort'     3     O(n*log(n))       0          no\n",
      "    'mergesort'    2     O(n*log(n))      ~n/2        yes\n",
      "    'timsort'      2     O(n*log(n))      ~n/2        yes\n",
      "    =========== ======= ============= ============ ========\n",
      "    \n",
      "    .. note:: The datatype determines which of 'mergesort' or 'timsort'\n",
      "       is actually used, even if 'mergesort' is specified. User selection\n",
      "       at a finer scale is not currently available.\n",
      "    \n",
      "    All the sort algorithms make temporary copies of the data when\n",
      "    sorting along any but the last axis.  Consequently, sorting along\n",
      "    the last axis is faster and uses less space than sorting along\n",
      "    any other axis.\n",
      "    \n",
      "    The sort order for complex numbers is lexicographic. If both the real\n",
      "    and imaginary parts are non-nan then the order is determined by the\n",
      "    real parts except when they are equal, in which case the order is\n",
      "    determined by the imaginary parts.\n",
      "    \n",
      "    Previous to numpy 1.4.0 sorting real and complex arrays containing nan\n",
      "    values led to undefined behaviour. In numpy versions >= 1.4.0 nan\n",
      "    values are sorted to the end. The extended sort order is:\n",
      "    \n",
      "      * Real: [R, nan]\n",
      "      * Complex: [R + Rj, R + nanj, nan + Rj, nan + nanj]\n",
      "    \n",
      "    where R is a non-nan real value. Complex values with the same nan\n",
      "    placements are sorted according to the non-nan part if it exists.\n",
      "    Non-nan values are sorted as before.\n",
      "    \n",
      "    .. versionadded:: 1.12.0\n",
      "    \n",
      "    quicksort has been changed to an introsort which will switch\n",
      "    heapsort when it does not make enough progress. This makes its\n",
      "    worst case O(n*log(n)).\n",
      "    \n",
      "    'stable' automatically choses the best stable sorting algorithm\n",
      "    for the data type being sorted. It, along with 'mergesort' is\n",
      "    currently mapped to timsort or radix sort depending on the\n",
      "    data type. API forward compatibility currently limits the\n",
      "    ability to select the implementation and it is hardwired for the different\n",
      "    data types.\n",
      "    \n",
      "    .. versionadded:: 1.17.0\n",
      "    \n",
      "    Timsort is added for better performance on already or nearly\n",
      "    sorted data. On random data timsort is almost identical to\n",
      "    mergesort. It is now used for stable sort while quicksort is still the\n",
      "    default sort if none is chosen. For details of timsort, refer to\n",
      "    `CPython listsort.txt <https://github.com/python/cpython/blob/3.7/Objects/listsort.txt>`_.\n",
      "    'mergesort' and 'stable' are mapped to radix sort for integer data types. Radix sort is an\n",
      "    O(n) sort instead of O(n log n).\n",
      "    \n",
      "    Examples\n",
      "    --------\n",
      "    >>> a = np.array([[1,4],[3,1]])\n",
      "    >>> np.sort(a)                # sort along the last axis\n",
      "    array([[1, 4],\n",
      "           [1, 3]])\n",
      "    >>> np.sort(a, axis=None)     # sort the flattened array\n",
      "    array([1, 1, 3, 4])\n",
      "    >>> np.sort(a, axis=0)        # sort along the first axis\n",
      "    array([[1, 1],\n",
      "           [3, 4]])\n",
      "    \n",
      "    Use the `order` keyword to specify a field to use when sorting a\n",
      "    structured array:\n",
      "    \n",
      "    >>> dtype = [('name', 'S10'), ('height', float), ('age', int)]\n",
      "    >>> values = [('Arthur', 1.8, 41), ('Lancelot', 1.9, 38),\n",
      "    ...           ('Galahad', 1.7, 38)]\n",
      "    >>> a = np.array(values, dtype=dtype)       # create a structured array\n",
      "    >>> np.sort(a, order='height')                        # doctest: +SKIP\n",
      "    array([('Galahad', 1.7, 38), ('Arthur', 1.8, 41),\n",
      "           ('Lancelot', 1.8999999999999999, 38)],\n",
      "          dtype=[('name', '|S10'), ('height', '<f8'), ('age', '<i4')])\n",
      "    \n",
      "    Sort by age, then height if ages are equal:\n",
      "    \n",
      "    >>> np.sort(a, order=['age', 'height'])               # doctest: +SKIP\n",
      "    array([('Galahad', 1.7, 38), ('Lancelot', 1.8999999999999999, 38),\n",
      "           ('Arthur', 1.8, 41)],\n",
      "          dtype=[('name', '|S10'), ('height', '<f8'), ('age', '<i4')])\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(np.sort)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 5, 3],\n",
       "       [2, 7, 4]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sort(array,axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 2, 1],\n",
       "       [0, 2, 1]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.argsort(array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [2 3 4]]\n",
      "2\n",
      "(2, 3)\n",
      "6\n",
      "int64\n"
     ]
    }
   ],
   "source": [
    "array = np.array([[1,2,3],\n",
    "                  [2,3,4]],dtype=np.int)\n",
    "\n",
    "print(array)\n",
    "print(array.ndim)\n",
    "print(array.shape)\n",
    "print(array.size)\n",
    "print(array.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1, 1],\n",
       "       [1, 1, 1, 1],\n",
       "       [1, 1, 1, 1]], dtype=int16)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.zeros(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10 12 14 16 18]\n",
      "[[0.71556334 0.79633194]\n",
      " [0.18829051 1.        ]]\n",
      "[[1.]\n",
      " [5.]\n",
      " [9.]]\n",
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]]\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(10,20,2)\n",
    "b = np.empty((2,2))\n",
    "c = np.linspace(1,9,3).reshape((3,1)) #等分\n",
    "d = np.arange(12).reshape((3,4))\n",
    "print(a)\n",
    "print(b)\n",
    "print(c)\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10 19 28 37]\n",
      "[10 21 32 43]\n",
      "[0 1 4 9]\n",
      "[-5.44021111  9.12945251 -9.88031624  7.4511316 ]\n",
      "[ True  True  True False]\n"
     ]
    }
   ],
   "source": [
    "A = np.array([10,20,30,40])\n",
    "B = np.arange(4)\n",
    "print(A-B)\n",
    "print(A+B)\n",
    "print(B**2) #2次方\n",
    "print(10*np.sin(A))\n",
    "print(B<3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 2]\n",
      " [0 3]]\n",
      "[[4 7]\n",
      " [2 3]]\n"
     ]
    }
   ],
   "source": [
    "aa = np.array([[1,2],\n",
    "              [0,1]])\n",
    "bb = np.arange(4).reshape((2,2))\n",
    "cc = aa*bb\n",
    "dd = np.dot(aa,bb)\n",
    "ee = aa.dot(bb)# ee == dd\n",
    "print(cc)\n",
    "print(dd)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[4.17022005e-01 7.20324493e-01 1.14374817e-04 3.02332573e-01]\n",
      " [1.46755891e-01 9.23385948e-02 1.86260211e-01 3.45560727e-01]]\n",
      "[[ 2  3  4  5]\n",
      " [ 6  7  8  9]\n",
      " [10 11 12 13]]\n",
      "[14 30 46]\n",
      "2\n",
      "0.00011437481734488664\n",
      "0.7203244934421581\n",
      "0.27633860870006827\n",
      "0.24429639200475534\n",
      "[ 2  5  9 14 20 27 35 44 54 65 77 90]\n",
      "[[1 1 1]\n",
      " [1 1 1]\n",
      " [1 1 1]]\n",
      "(array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2]), array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]))\n",
      "[[1.14374817e-04 3.02332573e-01 4.17022005e-01 7.20324493e-01]\n",
      " [9.23385948e-02 1.46755891e-01 1.86260211e-01 3.45560727e-01]]\n",
      "[[ 2  6 10]\n",
      " [ 3  7 11]\n",
      " [ 4  8 12]\n",
      " [ 5  9 13]]\n",
      "[[5 5 5 5]\n",
      " [6 7 8 9]\n",
      " [9 9 9 9]]\n"
     ]
    }
   ],
   "source": [
    "np.random.seed(1)\n",
    "ra = np.random.random((2,4))\n",
    "rb = np.arange(2,14).reshape((3,4))\n",
    "print(ra)\n",
    "print(rb)\n",
    "print(np.sum(rb,axis=1))#axis=0 列  axis=1 行\n",
    "print(np.argmin(ra))#最小值的下标\n",
    "print(np.min(ra))\n",
    "print(np.max(ra))\n",
    "print(np.average(ra)) # ra.mean()  平均数\n",
    "print(np.median(ra)) #中位数\n",
    "print(np.cumsum(rb)) #累加\n",
    "print(np.diff(rb)) #累差\n",
    "print(np.nonzero(rb))#非0的位置\n",
    "print(np.sort(ra))#一行行排序\n",
    "print(np.transpose(rb))#转置 rb.T\n",
    "print(np.clip(rb,5,9))#保留5和9之间的数 小于5的是5 大于9的是9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]]\n",
      "9\n",
      "[1.5 5.5 9.5]\n",
      "[4 5 6 7]\n",
      "[0 1 2 3]\n",
      "[4 5 6 7]\n",
      "[ 8  9 10 11]\n",
      "[0 4 8]\n",
      "[1 5 9]\n",
      "[ 2  6 10]\n",
      "[ 3  7 11]\n",
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n"
     ]
    }
   ],
   "source": [
    "xx = np.arange(12).reshape((3,4))\n",
    "print(xx)\n",
    "print(xx[2,1])#==xx[2][1]\n",
    "print(np.mean(xx,axis = 1))\n",
    "print(xx[1,:])#第1行所有数\n",
    "#一行行遍历\n",
    "for row in xx:  \n",
    "    print(row)\n",
    "#一列列遍历\n",
    "for column in xx.T:\n",
    "    print(column)\n",
    "#xx.flat变成列表  一个个遍历    \n",
    "for item in xx.flat:\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "#合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 1 1]\n",
      " [2 2 2]]\n",
      "[1 1 1 2 2 2]\n",
      "(3,)\n",
      "(3,)\n",
      "(3, 1)\n",
      "[[1 2]\n",
      " [1 2]\n",
      " [1 2]]\n",
      "(3,)\n"
     ]
    }
   ],
   "source": [
    "a1 = np.array([1,1,1])\n",
    "b1 = np.array([2,2,2])\n",
    "print(np.vstack((a1,b1)))#上下合并\n",
    "print(np.hstack((a1,b1)))#左右合并\n",
    "print(a1.shape)\n",
    "print(a1.T.shape)\n",
    "'''\n",
    "[1,1,1].T 不能变成 [[1]\n",
    "                 [1]\n",
    "                 [1]]\n",
    "'''\n",
    "print(a1[:,np.newaxis].shape)\n",
    "a2 = a1[:,np.newaxis]\n",
    "b2 = b1[:,np.newaxis]\n",
    "print(np.hstack((a2,b2)))\n",
    "print(b1.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1]\n",
      " [1]\n",
      " [1]\n",
      " [1]\n",
      " [1]\n",
      " [1]\n",
      " [2]\n",
      " [2]\n",
      " [2]\n",
      " [1]\n",
      " [1]\n",
      " [1]]\n"
     ]
    }
   ],
   "source": [
    "a1 = np.array([1,1,1])[:,np.newaxis]\n",
    "b1 = np.array([2,2,2])[:,np.newaxis]\n",
    "c1 = np.concatenate((a1,a1,b1,a1),axis =0 )\n",
    "print(c1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "#拆分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]]\n",
      "[array([[0, 1],\n",
      "       [4, 5],\n",
      "       [8, 9]]), array([[ 2,  3],\n",
      "       [ 6,  7],\n",
      "       [10, 11]])]\n",
      "[array([[0, 1, 2, 3]]), array([[4, 5, 6, 7]]), array([[ 8,  9, 10, 11]])]\n",
      "[array([[0, 1],\n",
      "       [4, 5],\n",
      "       [8, 9]]), array([[ 2],\n",
      "       [ 6],\n",
      "       [10]]), array([[ 3],\n",
      "       [ 7],\n",
      "       [11]])]\n",
      "[array([[0, 1, 2, 3]]), array([[4, 5, 6, 7]]), array([[ 8,  9, 10, 11]])]\n",
      "[array([[0, 1],\n",
      "       [4, 5],\n",
      "       [8, 9]]), array([[ 2,  3],\n",
      "       [ 6,  7],\n",
      "       [10, 11]])]\n"
     ]
    }
   ],
   "source": [
    "a3 = np.arange(12).reshape((3,4))\n",
    "print(a3)\n",
    "\n",
    "print(np.split(a3,2,axis=1)) #类似于左右分割\n",
    "print(np.split(a3,3,axis=0))  #上下分 不能进行不等的分割\n",
    "print(np.array_split(a3,3,axis=1))\n",
    "print(np.vsplit(a3,3)) #上下分\n",
    "print(np.hsplit(a3,2)) #左右分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "a4 = np.arange(3)\n",
    "b4 = a4 #浅复制\n",
    "c4 = a4.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1., 1.],\n",
       "       [1., 1., 1., 1.],\n",
       "       [1., 1., 1., 1.]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zeors = np.zeros([3,4])\n",
    "np.ones_like(zeors)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "[[100   2   3]\n",
      " [  4   5   6]]\n",
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "[[100   2   3]\n",
      " [  4   5   6]]\n"
     ]
    }
   ],
   "source": [
    "a = np.array([[1,2,3],[4,5,6]])\n",
    "a1 = np.array(a) #深拷贝\n",
    "a2 = np.asarray(a) #浅拷贝\n",
    "print(a)\n",
    "a[0,0] = 100\n",
    "print(a)\n",
    "print(a1)\n",
    "print(a2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0.,  10.,  20.,  30.,  40.,  50.,  60.,  70.,  80.,  90., 100.])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(0,100,11) #等差数列  最后参数是个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,\n",
       "       44, 46, 48])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arange(10,50,2) #等差数列 最后参数是间隔"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  1.,  10., 100.])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.logspace(0,2,3) #pow(10,n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.64043595, 0.86552769, 0.30631604, 0.07016009],\n",
       "       [0.54357725, 0.06607254, 0.4486993 , 0.64782027],\n",
       "       [0.49445656, 0.25965677, 0.26932075, 0.35734483]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.rand(3,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[16.23273121, 11.40519162, 12.47857451, 19.11777969],\n",
       "       [10.6211922 , 15.31357446, 14.29633623, 11.85630119],\n",
       "       [17.75877517, 17.63721675, 17.8483435 , 19.88624424]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.uniform(low=10,high=20,size=(3,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 4, 19, 12,  6, 10],\n",
       "       [15,  7, 14, 11,  3]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(1,20,(2,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlUAAAI/CAYAAABeaSyOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAVBUlEQVR4nO3dfaxtd13n8c/XXnxCHtQeCSOcuUxEMsRE0RuMcWQyZSAdagbUOoE4RHy6MQbFZ2vMjA8Tk86TjomTzDSIgxlEDYg6FJFGVCTBagu1KbSCYglFtJDOCM2MkMLXP85mctqe27PvPd+1e9ft65Xc9Ox91l7nu3/dt/d911p7t7o7AACczKc93AMAAFwKRBUAwABRBQAwQFQBAAwQVQAAA0QVAMCAU0vs9PLLL+/Tp08vsWsAgFE333zzh7t776T7WSSqTp8+nZtuummJXQMAjKqq903sx+k/AIABogoAYICoAgAYIKoAAAaIKgCAAaIKAGCAqAIAGCCqAAAGiCoAgAGiCgBggKgCABggqgAABogqAIABogoAYICoAgAYIKoAAAaIKgCAAaIKAGCAqAIAGCCqAAAGbBVVVfX4qnpNVd1RVbdX1VctPRgAwJqc2nK7n0vyxu6+uqo+PclnLzgTAMDqHBtVVfW4JM9K8pIk6e6PJ/n4smMBAKzLNqf/npLkQ0l+sareUVUvr6pHLzwXAMCqbHP671SSL0/y3d19Y1X9XJJrkvybwxtV1dkkZ5Nkf39/ek5gYaevuf5B99157VUPwyQA67TNkaq7ktzV3Tdubr8mB5F1P919XXef6e4ze3t7kzMCAFz0jo2q7v7rJO+vqqdt7np2knctOhUAwMps++6/707yqs07/96b5FuWGwkAYH22iqruviXJmYVnAQBYLZ+oDgAwQFQBAAwQVQAAA0QVAMAAUQUAMEBUAQAMEFUAAANEFQDAAFEFADBAVAEADBBVAAAD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feTkvxikp9ZZrxLynmvdR+cY39hkp+tqj9O8tEkn1hyyEvIA9f7g0n2u/sZSb4/yS9vjmqf02b9vc35eCdea7Z2orWuqh9Lcl+SVy065aXjgte7u3+su5+cg7V+6VHbHLbIxbJ1cBHu1yf5ikN3f2WSqzfXOjw+ySer6u+6++ePePzlSZ6Z5OuWmO9ScqFrXVV7Sb60u2/c3PWrSd64o7FX6SSv6+5+Ww7+tvSp6yK+eDdTr9dR693dH0vysc3XN1fVX+RgLR94Hc/fVNUTu/uDVfXEJHfvaOxVOuFacx5OutZV9ZIkX5uDazT9ZeEYg6/tV+Xg8zp//KF+3lLvQPrnSe7o7rs+dUd3///Da1X1E0nuPSqoNq7OwUVkf7fQfJeSC13r/53kcVX1xZtrfZ6T5PYdzLtmF/y6rqov6O67q+ozcnC68Kd3MO/aPWi9N38ZuKe7P1FV/yjJU5O894jH/laSb87BKe1vTvKbO5h3zU6y1pyfC17rqroyyQ8n+afd/X93NfDKnWS9n3rolOHzk9xx3A876UcqvDrJ25I8raruqqpv23zrhTmPU3dV9Ya6/1sVz+vxjwTTa7252PE7kry2qv40B9dU/dD03Gu00Ov6h6rq9iS3Jvlf3f3m0aFX7DzX+1lJbq2Dt0a/Jsl3dvc9m/28/NB1a9cmeU5VvScH/1F1vWCWWeuq+rrNdZlfleT6qvqdXTyXi91Cr+ufT/KYJDfUQ3wUwCPRUv8dqYOPwbk1yXOTvOzYORw9BAA4OZ+oDgAwQFQBAAwQVQAAA0QVAMAAUQUAMEBUAQAMEFUAAANEFQDAgL8H/avdMQp7EwsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 720x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.random.normal(175,0.1,60)\n",
    "import matplotlib.pyplot as plt\n",
    "plt.figure(figsize=(10,10))\n",
    "plt.hist(x,100)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_change = np.random.normal(0,1,(3,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.04683226, -0.19290259, -0.71556334, -0.79633194],\n",
       "       [ 1.89664245, -0.1066889 ,  0.3783841 , -0.18829051],\n",
       "       [ 0.8987807 ,  0.11944445,  0.22190152,  0.23829994]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.04683226, -0.19290259, -0.71556334])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change[0,0:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.04683226, -0.19290259, -0.71556334],\n",
       "       [-0.79633194,  1.89664245, -0.1066889 ],\n",
       "       [ 0.3783841 , -0.18829051,  0.8987807 ],\n",
       "       [ 0.11944445,  0.22190152,  0.23829994]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change.resize([4,3]) #不是转置\n",
    "stock_change"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.04683226, -0.19290259, -0.71556334],\n",
       "       [-0.79633194,  1.89664245, -0.1066889 ],\n",
       "       [ 0.3783841 , -0.18829051,  0.8987807 ],\n",
       "       [ 0.11944445,  0.22190152,  0.23829994]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change.reshape([4,-1]) #stock_change不变化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.04683226, -0.19290259, -0.71556334],\n",
       "       [-0.79633194,  1.89664245, -0.1066889 ],\n",
       "       [ 0.3783841 , -0.18829051,  0.8987807 ],\n",
       "       [ 0.11944445,  0.22190152,  0.23829994]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.04683226, -0.79633194,  0.3783841 ,  0.11944445],\n",
       "       [-0.19290259,  1.89664245, -0.18829051,  0.22190152],\n",
       "       [-0.71556334, -0.1066889 ,  0.8987807 ,  0.23829994]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 0],\n",
       "       [0, 1, 0],\n",
       "       [0, 0, 0],\n",
       "       [0, 0, 0]], dtype=int32)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change.astype(np.int32)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1,  2,  3,  4,  5, 23])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([[1,23,4,5],[1,2,3,4]])\n",
    "np.unique(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.04683226, -0.19290259, -0.71556334],\n",
       "       [-0.79633194,  1.89664245, -0.1066889 ],\n",
       "       [ 0.3783841 , -0.18829051,  0.8987807 ],\n",
       "       [ 0.11944445,  0.22190152,  0.23829994]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.        , -0.19290259, -0.71556334],\n",
       "       [-0.79633194,  1.        , -0.1066889 ],\n",
       "       [ 1.        , -0.18829051,  1.        ],\n",
       "       [ 1.        ,  1.        ,  1.        ]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change[stock_change>0] = 1\n",
    "stock_change"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.all(stock_change>-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.any(stock_change==1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 0, 0],\n",
       "       [0, 1, 0],\n",
       "       [1, 0, 1],\n",
       "       [1, 1, 1]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.where(stock_change>=1,1,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.        , -0.19290259, -0.71556334],\n",
       "       [-0.79633194,  1.        , -0.1066889 ],\n",
       "       [ 1.        , -0.18829051,  1.        ],\n",
       "       [ 1.        ,  1.        ,  1.        ]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.where(np.logical_and(stock_change>0.5,stock_change<=1),5,0)\n",
    "stock_change"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.79633194, -0.19290259, -0.71556334])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change.min(axis=0) #axis=0 每列中的最小值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.71556334, -0.79633194, -0.18829051,  1.        ])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change.min(axis=1) #axis=0 每行中的最小值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 0, 0])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_change.argmin(axis = 0) #axis=0 每列中的最小值下标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 3, 4],\n",
       "       [7, 8, 9]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#广播机制\n",
    "a = np.array([[1,2,3],[4,5,6]])\n",
    "b = np.array([[1],[3]])\n",
    "a+b"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
